<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>去除前缀并排序</title>
    <style>
        /* 页面基本样式 */
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f3f4f6;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            color: #333;
        }

        .container {
            text-align: center;
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            width: 80%;
            max-width: 600px;
        }

        h1 {
            font-size: 24px;
            color: #4CAF50;
            margin-bottom: 20px;
        }

        textarea {
            width: 100%;
            height: 100px;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            resize: none;
            font-size: 16px;
            margin-bottom: 20px;
        }

        button {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 12px 30px;
            font-size: 16px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #45a049;
        }

        .result {
            margin-top: 20px;
            padding: 15px;
            background-color: #f9f9f9;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            white-space: pre-wrap;
            word-wrap: break-word;
        }

        .result span {
            display: block;
            margin: 5px 0;
            font-size: 16px;
            color: #555;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>去除前缀并排序</h1>
        <textarea id="inputText" placeholder="请输入带有前缀的字符串，多个字符串请用换行隔开"></textarea>
        <button id="processBtn">处理并排序</button>
        <div class="result" id="resultDisplay">
            <strong>处理结果：</strong>
            <span>请输入字符串并点击“处理并排序”按钮。</span>
        </div>
    </div>

    <script>
        // 去除前缀并排序的主函数
        function removePrefixSort(sortArr) {
            return sortArr.sort((a, b) => (delPrefix(a) > delPrefix(b) ? 1 : -1));
        }

        // 去除前缀函数
        function delPrefix(item) {
            return item.replace(/^(xtt|code|js)-/, '');
        }

        // 获取按钮和显示结果的容器
        const processBtn = document.getElementById('processBtn');
        const resultDisplay = document.getElementById('resultDisplay');
        const inputText = document.getElementById('inputText');

        // 按钮点击事件
        processBtn.addEventListener('click', () => {
            // 获取用户输入的文本
            const inputValue = inputText.value.trim();

            // 如果输入为空，提示用户输入数据
            if (!inputValue) {
                resultDisplay.innerHTML = '<strong>处理结果：</strong><span>请输入字符串并点击“处理并排序”按钮。</span>';
                return;
            }

            // 将输入按行拆分成数组
            const inputArr = inputValue.split('\n').map(item => item.trim()).filter(item => item !== '');

            // 使用 removePrefixSort 排序
            const sortedArr = removePrefixSort(inputArr);

            // 显示排序后的结果
            resultDisplay.innerHTML = '<strong>处理结果：</strong>';
            sortedArr.forEach(item => {
                resultDisplay.innerHTML += `<span>${item}</span>`;
            });
        });
    </script>

</body>

</html>